﻿using System;
using System.Net;
using Terraria.GameContent.UI.Elements;
using Terraria.Localization;
using Terraria.UI;

namespace Terraria.ModLoader.UI
{
	// Token: 0x020002B9 RID: 697
	internal class UIUploadMod : UIState
	{
		// Token: 0x06001B6E RID: 7022 RVA: 0x00430EA4 File Offset: 0x0042F0A4
		public override void OnInitialize()
		{
			this.loadProgress = new UILoadProgress();
			this.loadProgress.Width.Set(0f, 0.8f);
			this.loadProgress.MaxWidth.Set(600f, 0f);
			this.loadProgress.Height.Set(150f, 0f);
			this.loadProgress.HAlign = 0.5f;
			this.loadProgress.VAlign = 0.5f;
			this.loadProgress.Top.Set(10f, 0f);
			base.Append(this.loadProgress);
			UITextPanel<string> uitextPanel = new UITextPanel<string>(Language.GetTextValue("UI.Cancel"), 0.75f, true);
			uitextPanel.VAlign = 0.5f;
			uitextPanel.HAlign = 0.5f;
			uitextPanel.Top.Set(170f, 0f);
			uitextPanel.OnMouseOver += UICommon.FadedMouseOver;
			uitextPanel.OnMouseOut += UICommon.FadedMouseOut;
			uitextPanel.OnClick += this.CancelClick;
			base.Append(uitextPanel);
		}

		// Token: 0x06001B6F RID: 7023 RVA: 0x00013B55 File Offset: 0x00011D55
		public override void OnActivate()
		{
			this.loadProgress.SetText("Uploading: " + this.name);
			this.loadProgress.SetProgress(0f);
		}

		// Token: 0x06001B70 RID: 7024 RVA: 0x00013B82 File Offset: 0x00011D82
		internal void SetDownloading(string name)
		{
			this.name = name;
		}

		// Token: 0x06001B71 RID: 7025 RVA: 0x00013B8B File Offset: 0x00011D8B
		public void SetCancel(Action cancelAction)
		{
			this.cancelAction = cancelAction;
		}

		// Token: 0x06001B72 RID: 7026 RVA: 0x00013B94 File Offset: 0x00011D94
		internal void SetProgress(UploadProgressChangedEventArgs e)
		{
			this.SetProgress(e.BytesSent, e.TotalBytesToSend);
		}

		// Token: 0x06001B73 RID: 7027 RVA: 0x00013BA8 File Offset: 0x00011DA8
		internal void SetProgress(long count, long len)
		{
			UILoadProgress uiloadProgress = this.loadProgress;
			if (uiloadProgress == null)
			{
				return;
			}
			uiloadProgress.SetProgress((float)count / (float)len);
		}

		// Token: 0x06001B74 RID: 7028 RVA: 0x00013BBF File Offset: 0x00011DBF
		private void CancelClick(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(10, -1, -1, 1, 1f, 0f);
			this.cancelAction();
		}

		// Token: 0x04001889 RID: 6281
		private UILoadProgress loadProgress;

		// Token: 0x0400188A RID: 6282
		private string name;

		// Token: 0x0400188B RID: 6283
		private Action cancelAction;
	}
}
